package com.rocpenghua.codec;

import com.rocpenghua.codec.sm4Simple.HexUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.StringUtils;

/**
 * @author pengp
 * @date 2022年04月19日 10:01
 */
public class Base64Util {
    public static String encode(String source) {
        return Base64.encodeBase64String(StringUtils.getBytesUtf8(source));
    }
    public static String decode(String target) {
        return StringUtils.newStringUtf8(Base64.decodeBase64(target));
    }
    public static String encrypt(String source) {
        return HexUtil.getHexString(Base64.encodeBase64String(StringUtils.getBytesUtf8(source)).getBytes());
    }
    public static String decrypt(String target) {
        return StringUtils.newStringUtf8(Base64.decodeBase64(new String(HexUtil.hexStringToBytes(target))));
    }
}

